function [LLH_LHH,rej_num,targ_num,third_num,had_did,pos_neg,rejkeep_low_high,cor_notcor,objs,rej_item,targ_item,third_item,quest_words,quest_item,obj_text,targ_text,quest_text,item_1,item_2,item_3,image_1,image_2,image_3,rej_img] = generate_stim(cond_mat,cur_run,cur_trial,rej_keep,cur_name,images,cur_vers,low_set,high_set)


%Critical Trials: 1-8
%Foil Trials: 11-14

%In cur_vers matrix:
%col 1=had_did
%col 2=pos_neg (value of 0 means randomly select 1 or 2)
%col 3=cor_notcor (value of 0 means randomly select 1 or 2)
%col 4=rej_item
%col 5=targ_item
%col 6=third_item

trial_row=cond_mat(cur_run,cur_trial);

if rej_keep==1
    if(trial_row==11||trial_row==12)
        LLH_LHH=2;
    else
        LLH_LHH=1;
    end
else
    if(trial_row==11||trial_row==12)
        LLH_LHH=1;
    else
        LLH_LHH=2;
    end
end
    



%%
%ITEM SELECTION
%combine object arrays into a single array
if rej_keep==1 %if it is a reject trial, make the low set the first half of the array
    objs=low_set;
    objs{4}=high_set{1};
    objs{5}=high_set{2};
    objs{6}=high_set{3};
else
    objs=high_set; %if it is a keep trial, make the high set the first half of the array
    objs{4}=low_set{1};
    objs{5}=low_set{2};
    objs{6}=low_set{3};
end

%select the appropriate item from the array
rej_num=cur_vers(trial_row,4);
rej_item=objs(rej_num);
targ_num=cur_vers(trial_row,5);
targ_item=objs(targ_num);
third_num=cur_vers(trial_row,6);
third_item=objs(third_num);

if rej_keep==1 
    if rej_num<4
        rejkeep_low_high=1;
    else rejkeep_low_high=2;
    end
else rej_keep==2
    if rej_num<4
        rejkeep_low_high=2;
    else rejkeep_low_high=1;
    end
end

%convert items from cells to strings
targ_item=targ_item{1};
rej_item=rej_item{1};
third_item=third_item{1};

%%
%HAD VS DID/POS VS NEG
if rej_keep==1
word_set={'HAD TO REJECT','DIDN''T HAVE TO REJECT','REJECTED','DIDN''T REJECT'};
else
    word_set={'HAD TO KEEP','DIDN''T HAVE TO KEEP','KEPT','DIDN''T KEEP'};
end

if cur_vers(trial_row,1)==1 %if it is a had trial
    if cur_vers(trial_row,2)==1 %if it is a positive trial
        word_set_num=1; %pick 'had to reject'
    else if cur_vers(trial_row,2)==2 %if it is a negative trial
            word_set_num=2; %pick didn't have to reject
        else word_set_num=datasample([1,2],1); %otherwise randomly select between the two
        end
    end
else if cur_vers(trial_row,1)==2 %if it is a did trial
    if cur_vers(trial_row,2)==1 %if it is a positive trial
        word_set_num=3; %pick 'rejected'
    else if cur_vers(trial_row,2)==2 %if it is a negative trial
            word_set_num=4; %pick 'didn't reject'
        else word_set_num=datasample([3,4],1); %otherwise randomly select between the two
        end
    end
    end
end

quest_words=word_set{word_set_num};

%get data on had vs did and pos vs neg
if word_set_num<=2
    had_did=1;
else had_did=2;
end

if (word_set_num==1) || (word_set_num==3)
    pos_neg=1;
else pos_neg=2;
end

%%
%SPECIFY THE QUESTION ITEM
%specify whether question should ask about the wrong or right item
if cur_vers(trial_row,3)==1
    cor_notcor=1;
    quest_item=rej_item;
    else cor_notcor=datasample([1,2],1); %on trials where it is not specified randomly select whether or not the wrong or right item will be asked about 
        if cor_notcor==1;
            quest_item=rej_item;
        else quest_item=third_item;
        end
end






%%
%Create the specific sentances
obj_text=[cur_name,'''s survival pack contains:'];
order_pick=randperm(6,1);
if order_pick==1
item_1=rej_item;
item_2=targ_item;
item_3=third_item;
else if order_pick==2
        item_1=rej_item;
        item_2=third_item;
        item_3=targ_item;
    else if order_pick==3
            item_1=targ_item;
            item_2=rej_item;
            item_3=third_item;
        else if order_pick==4
                item_1=targ_item;
                item_2=third_item;
                item_3=rej_item;
            else if order_pick==5
                    item_1=third_item;
                    item_2=rej_item;
                    item_3=targ_item;
                else
                    item_1=third_item;
                    item_2=targ_item;
                    item_3=rej_item;
                end
            end
        end
    end
end

%designate the correct image to go with the item words
if strcmp(item_1,'stuffed animal')
    image_1=images.teddy;
else if strcmp(item_1,'ring')
        image_1=images.ring;
    else if strcmp(item_1,'nail polish')
            image_1=images.polish;
        else if strcmp(item_1,'axe')
                image_1=images.axe;
            else if strcmp(item_1,'fishing pole')
                    image_1=images.pole;
                else
                    image_1=images.matches;
                end
            end
        end
    end
end

if strcmp(item_2,'stuffed animal')
    image_2=images.teddy;
else if strcmp(item_2,'ring')
        image_2=images.ring;
    else if strcmp(item_2,'nail polish')
            image_2=images.polish;
        else if strcmp(item_2,'axe')
                image_2=images.axe;
            else if strcmp(item_2,'fishing pole')
                    image_2=images.pole;
                else
                    image_2=images.matches;
                end
            end
        end
    end
end

if strcmp(item_3,'stuffed animal')
    image_3=images.teddy;
else if strcmp(item_3,'ring')
        image_3=images.ring;
    else if strcmp(item_3,'nail polish')
            image_3=images.polish;
        else if strcmp(item_3,'axe')
                image_3=images.axe;
            else if strcmp(item_3,'fishing pole')
                    image_3=images.pole;
                else
                    image_3=images.matches;
                end
            end
        end
    end
end


%Screen 2
if rej_keep==1
targ_text=['After considering all three options,\n',cur_name,' decided to reject the:\n\n',rej_item];
else
    targ_text=['After considering all three options,\n',cur_name,' decided to keep the:\n\n',rej_item];
end


if strcmp(rej_item,'stuffed animal')
    rej_img=images.teddy;
else if strcmp(rej_item,'ring')
        rej_img=images.ring;
    else if strcmp(rej_item,'nail polish')
            rej_img=images.polish;
        else if strcmp(rej_item,'axe')
                rej_img=images.axe;
            else if strcmp(rej_item,'fishing pole')
                    rej_img=images.pole;
                else
                    rej_img=images.matches;
                end
            end
        end
    end
end


%Screen 3
choices='Strongly disagree            Neutral            Strongly agree\n\n1          2          3         4          5';
seems_think=randperm(2,1);
if seems_think==1
    quest_text=(['''''Seems like ',cur_name,' ',quest_words,' the ',quest_item,'.''''\n\n\n\n',choices]);
else quest_text=(['''''I think ',cur_name,' ',quest_words,' the ',quest_item,'.''''\n\n\n\n',choices]);
end

